package com.decent.ejfadmin.common.bean;


import com.decent.ejfadmin.common.enums.ErrorCode;
import com.decent.ejfadmin.common.exception.ErrorCodeException;

import java.util.HashMap;

/**
 * describe:返回公共类
 *
 * @author 陈豆豆
 * @date 2019/09/07
 */
public final class MemberMessage extends HashMap<String, Object> {

    @SuppressWarnings("WeakerAccess")
    public static ThreadLocal<MemberMessage> messageThreadContext = new ThreadLocal<>();

    public MemberMessage() {

    }

    public MemberMessage(int status) {
        this.put("status", status);
        messageThreadContext.set(this);
    }

    public MemberMessage(Exception e) {
        if (e instanceof ErrorCodeException) {
            this.put("status", Integer.valueOf(e.getMessage()));
        } else {
            this.put("status", ErrorCode.SYSTEM_ERROR);
        }
        messageThreadContext.set(this);
    }

    public static String toString(int status) {
        return "{\"status\":" + status + "}";
    }

}
